﻿/*************************************************
作者: Plane
邮箱: 1785275942@qq.com
功能: 声音管理服务

           ~~获取更多教学资讯~~
//----------------*----------------\\
        教学官网：www.qiqiker.com
        官方微信服务号: qiqikertuts
        Plane老师微信: PlaneZhong
\\----------------*----------------//
*************************************************/

using UnityEngine;

public class AudioSvc : ILogic {
    //-------------Declaration----------------//
    PERoot root; ResSvc resSvc;
    public bool TurnOnVoice = true;
    AudioSource bgAudio;
    AudioSource uiAudio;

    //-------------Flow Functions-------------//
    public void Init() {
        root = PERoot.Instance;
        resSvc = root.resSvc;

        bgAudio = root.transform.Find("BGAudio").GetComponent<AudioSource>();
        uiAudio = root.transform.Find("UIAudio").GetComponent<AudioSource>();

        this.Log("Init AudioSvc Done.");
    }
    public void Tick() {
        if (Input.GetKeyDown(KeyCode.F1)) {
            TurnOnVoice = true;
        }
        else if (Input.GetKeyDown(KeyCode.F2)) {
            TurnOnVoice = false;
        }
    }
    public void UnInit() {
        this.Log("UnInit AudioSvc.");
    }

    //-------------Tool Functions-------------//
    public void PlayUIAudio(string name) {
        if (!TurnOnVoice) {
            return;
        }

        AudioClip clip = resSvc.LoadAudio($"{PathDefine.AudioPath}{name}", true);
        uiAudio.clip = clip;
        uiAudio.Play();
    }
}